package master.ghrm.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Transient;

@Entity
public class GradableQuestionAnswer extends Answer {

	private static final long serialVersionUID = 1L;

	private static final String[] EXCL_ADD = { "question" };

	private Integer gradingAnswer;

	private GradableQuestion question;

	/**
	 * Default constructor, mostly for persistence use.
	 */
	public GradableQuestionAnswer() {
		super();
	}

	/**
	 * @param aQuestion gradable question.
	 * @param assessment assessment this answer belongs to.
	 */
	public GradableQuestionAnswer(GradableQuestion aQuestion, Assessment assessment) {
		super();
		this.question = aQuestion;
		this.setAssessment(assessment);
	}

	/**
	 * @return the gradingAnswer
	 */
	@Column(name = "grading_answer")
	public Integer getGradingAnswer() {
		return this.gradingAnswer;
	}

	/**
	 * @param aGradingAnswer the gradingAnswer to set
	 */
	public void setGradingAnswer(Integer aGradingAnswer) {

		this.gradingAnswer = aGradingAnswer;
	}

	/**
	 * @return the question
	 */
	@Override
	@Transient
	public GradableQuestion getQuestion() {
		return this.question;
	}

	/**
	 * @param aQuestion the question to set
	 */
	@Override
	public void setQuestion(Question aQuestion) {
		this.question = (GradableQuestion) aQuestion;
	}

	/**
	 * @return string value of the grade.
	 */
	@Override
	public String toString() {
		if (gradingAnswer == null) {
			gradingAnswer = Integer.valueOf(1);
		}
		return getAnswerLabel();
	}

	@Override
	@Transient
	protected String[] getAdditionalExclAttr() {
		return GradableQuestionAnswer.EXCL_ADD;
	}

	@Transient
	public String getAnswerLabel() {
		return question.getLabelForValue(gradingAnswer);
	}
}
